import org.junit.jupiter.api.Test;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class _16_最接近的三数之和__暴力解法 {

    @Test
    void test(){
        int []nums = {0,0,0,0};
        System.out.println(threeSumClosest(nums, 1));
    }


    public int threeSumClosest(int[] nums, int target) {
        Set<Integer> set =new HashSet();
        int min=Integer.MAX_VALUE;
        int number=0;
        for (int i = 0; i < nums.length; i++) {
            for (int j = i+1; j < nums.length; j++) {
                for (int k = j+1; k < nums.length; k++) {
                    int total = nums[i] + nums[j] + nums[k];
                    set.add(total);

                }
            }
        }
        for (Integer o : set) {
            if (Math.abs(o - target) < Math.abs(min)) {
                min = o - target;
                number=o;
            }
        }
        return number;

    }
}
